# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/18 10:01 
@Author  : ZhangShenao 
@File    : 2.使用OpenAIEmbedding生成文本嵌入.py
@Desc    : 使用OpenAIEmbedding生成文本嵌入
"""
import os

import dotenv
from langchain_openai import OpenAIEmbeddings

dotenv.load_dotenv()

embeddings = OpenAIEmbeddings(
    model='text-embedding-3-small',
    dimensions=1024,  # assign dimensions to 1024
    openai_api_base=os.getenv('OPENAI_API_BASE')
)

text = 'This is a test document.'
vector = embeddings.embed_documents([text])
print(f'the dimension of vector is {len(vector[0])}')
print(vector[0][:11])
